const path = require('path');
const express = require('express');
const logger = require('morgan');

// 导入路由
const usersRouter = require('./routes/users');
const exploreRouter = require('./routes/explore');
const fileRouter = require('./routes/files');

// 指定端口
const port = 3000;
// 创建应用(application)
const app = express();

// 启用日志中间件
app.use(logger('dev'));
// 启用处理`application/json`请求体的中间件
app.use(express.json());
// 启用处理`application/x-www-form-urlencoded`请求体的中间件
app.use(express.urlencoded({ extended: false }));
// 启用处理`text/plain`请求体的中间件
app.use(express.text());
// 启用处理静态文件的中间件
app.use(express.static(path.join(__dirname, 'public')));

// 挂载路由
app.use( usersRouter );
app.use( exploreRouter );
app.use( fileRouter );

// 启动监听
app.listen( port ,() => console.log( `正在监听${port}端口` ) );